#ifndef CH_SUBCLASSWND_H
#define CH_SUBCLASSWND_H

#pragma once

class AFX_EXT_CLASS CHSubclassWnd : public CObject 
{
public:
	DECLARE_DYNAMIC(CHSubclassWnd);
	CHSubclassWnd();
	~CHSubclassWnd();

	// Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY)
	BOOL	HookWindow(HWND  hwnd);
	BOOL	HookWindow(CWnd* pWnd)	{ return HookWindow(pWnd->GetSafeHwnd()); }
	BOOL	IsHooked()					{ return m_hWnd!=NULL; }

	friend LRESULT CALLBACK CHHookWndProc(HWND, UINT, WPARAM, LPARAM);
	friend class CHSubclassWndMap;

#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	HWND			m_hWnd;				// the window hooked
	WNDPROC			m_pOldWndProc;		// ..and original window proc
	CHSubclassWnd*	m_pNext;			// next in chain of hooks for this window

	// Override this to handle messages in specific handlers
	virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
	LRESULT Default();				// call this at the end of handler fns
};

#endif // CH_SUBCLASSWND_H

